package com.me.libgdx_test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class ClassObjectShopDungeon extends AbstractClassObjectDungeon{
	private ArrayList<ClassDungeonShop> shop;
	//private int price;
	private Random random = new Random(System.currentTimeMillis());
	private ClassLogDisplay logger;
	ClassObjectShopDungeon(ArrayList<ClassDungeonShop> shop, float price, float discount){
		this.shop = new ArrayList<ClassDungeonShop>(shop);
		this.logger = new ClassLogDisplay("ClassObjectShopDungeon");
		for(ClassDungeonShop item:shop){
			logger.print("Price: " + price + " Discount: " + discount);
			float final_price = (price * 5f) * discount;
			final_price = final_price < 1 ? 1:final_price;
			item.set_price((int)final_price);
		}
	}
	public ClassDungeonShop get_shop_info(int index){
		return shop.get(index);
	}
	public void set_price(int price){
		for(ClassDungeonShop item:shop){
			item.set_price(price);
		}
	}
	public int get_price(int index){
		return shop.get(index).price;
	}
	public boolean special_shop(){
		boolean special = false;
		for(ClassDungeonShop item:shop){
			//If there is an upgradeable item being sold here...
			if(item.upgrade_string.length>1){
				special = true;
			}
		}
		return special;
	}
	public String get_shop_name(){
		if(special_shop()){
			return "Special Shop";
		}
		return "Normal Shop";
	}
	public String get_shop_details(){
		if(special_shop()){
			return "This Shop Sells Special Items...";
		}
		return "This Shop Sells Normal Items";
	}
	public String get_shop_disclaimer(){
		return "Click On The Board To Exit The Shop";
	}
	public void move_player_shop(ClassCharacterPlayer player){
		player.location = this.get_location();
	}
	public void use_shop(ClassCharacterPlayer player, int shop_item){
		if(player.gold >= shop.get(shop_item).price && !shop.get(shop_item).purchased){
			if(modify_player(player, shop_item)){
				player.add_god_action("bought_goods");
				player.gold -= shop.get(shop_item).price;
				shop.get(shop_item).purchased = true;
				//price = 0;
				this.shop.get(shop_item).Description = "Sold Out";
				this.shop.get(shop_item).shop_image = "loc_shop_used.png";
			}
		}
	}
	public boolean all_used(){
		for(ClassDungeonShop item:shop){
			if(!item.purchased){
				return false;
			}
		}
		return true;
	}
	public String get_shop_image(){
		if(all_used()){
			return "loc_shop_used.png";
		}
		return "loc_shop.png";
	}
	public boolean modify_player(ClassCharacterPlayer player, int shop_index){
		player.set_location(this.get_location());
		if(shop.get(shop_index).Name == "Mana Potion"){
			player.set_player_variable("mana_potions", (int) player.get_player_variable("mana_potions")+1);
			return true;
		}
		if(shop.get(shop_index).Name == "Health Potion"){
			player.set_player_variable("health_potions", (int) player.get_player_variable("health_potions")+1);
			return true;
		}
		if(shop.get(shop_index).Name == "Attack"){
			player.set_player_variable("attack", (int) player.get_player_variable("attack")+2+shop.get(shop_index).tech_level);
			return true;
		}
		if(shop.get(shop_index).Name == "Health"){
			player.set_player_variable("max_health", (int) player.get_player_variable("max_health")+5+shop.get(shop_index).tech_level);
			return true;
		}
		if(shop.get(shop_index).Name == "Mana"){
			player.set_player_variable("max_mana", (int) player.get_player_variable("max_mana")+5+shop.get(shop_index).tech_level);
			return true;
		}
		if(shop.get(shop_index).Name == "Exp"){
			player.set_player_variable("current_exp", (int) player.get_player_variable("current_exp")+5+shop.get(shop_index).tech_level);
			return true;
		}
		if(shop.get(shop_index).Name == "Life"){
			if(player.get_player_variable("lives")==1){
				return false;
			}
			player.set_player_variable("lives", (int) player.get_player_variable("lives")+1);
			return true;
		}
		if(shop.get(shop_index).Name == "Full Heal"){
			if(player.get_player_variable("current_health")==player.get_player_variable("max_health")){
				return false;
			}
			player.set_player_variable("current_health", player.get_max_health());
			return true;
		}
		if(shop.get(shop_index).Name == "Full Restore"){
			if(player.get_player_variable("current_mana")==player.get_player_variable("max_mana")){
				return false;
			}
			player.set_player_variable("current_mana", player.get_player_variable("max_mana"));
			return true;
		}
		if(shop.get(shop_index).Name.contains("Shield")){
			if(shop.get(shop_index).tech_level==10){
				player.set_immune_mod("Poison", true);
			}
			if(shop.get(shop_index).tech_level>7){
				player.set_immune_mod("Amnesia", true);
			}
			if(shop.get(shop_index).tech_level>4){
				player.set_immune_mod("Mana Burn", true);
			}
			if(shop.get(shop_index).tech_level>2){
				player.set_immune_mod("Weakness", true);
			}
			player.set_immune_mod("Blind", true);
			return true;
		}	
		if(shop.get(shop_index).Name.contains("Armor")){
			player.set_player_variable_float("phys_def", player.get_player_variable_float("phys_def") + (.025f * (float)(shop.get(shop_index).tech_level+1)));
			return true;
		}
		if(shop.get(shop_index).Name.contains("Helm")){
			player.set_player_variable_float("mag_def", player.get_player_variable_float("mag_def") + (.025f * (float)(shop.get(shop_index).tech_level+1)));
			return true;
		}
		if(shop.get(shop_index).Name.contains("Boots")){
			player.set_player_variable_float("dodge", player.get_player_variable_float("dodge") + (.015f * (float)(shop.get(shop_index).tech_level+1)));
			return true;
		}
		if(shop.get(shop_index).Name.contains("Gloves")){
			int increase = shop.get(shop_index).tech_level == 10?4:shop.get(shop_index).tech_level/3;
			player.get_class_mods().playerShroudMod.restore_health = player.get_class_mods().playerShroudMod.restore_health + increase;
			player.get_class_mods().playerShroudMod.restore_mana = player.get_class_mods().playerShroudMod.restore_mana + increase;
			return true;
		}
		if(shop.get(shop_index).Name.contains("Staff")){
			player.set_player_variable_float("mag_atk", player.get_player_variable_float("mag_atk") + (float)((.025f * (shop.get(shop_index).tech_level+1))));
			return true;
		}
		if(shop.get(shop_index).Name.contains("Sword")){
			player.set_player_variable_float("phys_atk", player.get_player_variable_float("phys_atk") + (float)((.025f * (shop.get(shop_index).tech_level+1))));
			return true;
		}
		if(shop.get(shop_index).Name.contains("Mace")){
			player.set_player_variable_float("double_hit", player.get_player_variable_float("double_hit") + (float)((.025f * (shop.get(shop_index).tech_level+1))));
			return true;
		}
		if(shop.get(shop_index).Name.contains("Dice")){
			player.upper_bounds += (.25f * (shop.get(shop_index).tech_level+1));
			if(!player.get_class_mods().playerAttackMod.attack_mods.contains("gambler")){
				player.get_class_mods().playerAttackMod.attack_mods.add("gambler");
			}
			return true;
		}
		if(shop.get(shop_index).Name.contains("Scope")){
			if(shop.get(shop_index).tech_level==10){
				player.get_class_mods().playerShroudMod.half_shroud = true;
			}else{	
				if(shop.get(shop_index).tech_level>7){
					if(!player.get_class_mods().playerShroudMod.see_through_shrouds.contains("enemy_lower")){
						player.get_class_mods().playerShroudMod.see_through_shrouds.add("enemy_lower");
					}
				}
				if(shop.get(shop_index).tech_level>4){
					if(!player.get_class_mods().playerShroudMod.see_through_shrouds.contains("spell")){
						player.get_class_mods().playerShroudMod.see_through_shrouds.add("spell");
					}
				}
				if(shop.get(shop_index).tech_level>2){
					if(!player.get_class_mods().playerShroudMod.see_through_shrouds.contains("shop")){
						player.get_class_mods().playerShroudMod.see_through_shrouds.add("shop");
					}
				}
				if(!player.get_class_mods().playerShroudMod.see_through_shrouds.contains("item")){
					player.get_class_mods().playerShroudMod.see_through_shrouds.add("item");
				}
			}
			return true;
		}
		logger.print("Shop Info for: " + shop.get(shop_index).Name + " not found. Please correct and try again.");
		return false;
	}

}
